package study.spring.condition.animal;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.util.MultiValueMap;

public class OnAnimal implements Condition {

    @Override
    public boolean matches(ConditionContext context,
                           AnnotatedTypeMetadata metadata) {

        MultiValueMap<String, Object> attr = metadata.getAllAnnotationAttributes(ConditionOnAnimal.class.getName());
        String kind = (String) attr.getFirst("kind");
        if ("dog".equalsIgnoreCase(kind)) {
            return true;
        }
        return false;
    }
}
